package com.ubs.ejb;
import javax.ejb.Local;

import com.ubs.dom.Account;
import com.ubs.scurity.UbsSecuityException;

@Local
public interface AccountControllerLocal extends DiagnosticCompatibleBean {
	
	/**
	 * <p>
	 * This method looks up given login in 'account' table and 
	 * return true, if some account is already registered with 
	 * such login.
	 * </p>
	 * <p>
	 * In generally, this method is developed to check that the login
	 * is free and can be used for new account registration.
	 * </p>
	 * @param login - the user login.
	 * @return true, in case given login is stored in 'account' table.
	 */
	boolean doesLoginExist(String login);
	
	/**
	 * <p>
	 * adds new account record into 'account' table.
	 * </p>
	 * <p>
	 * Note: this method doesn't check that an account login is already 
	 * busy by anther account, so {@link AccountControllerLocal#doesLoginExist(String)}
	 * has to be used before this method.
	 * </p>
	 * @param account - new account to store
	 */
	void registerAccount(Account account);

	Account loginAccount(String login, String passwordMD5);
	
	void updateProfile(Account account) throws UbsSecuityException;
	
	/**
	 * <p>This method adds/removes deltaSum to/from balance of account 
	 * with given accountId. 
	 * </p>
	 * <p>
	 * This method uses the update statement to avoid data corruption via 
	 * concurrence racing.
	 * </p>
	 * <p><b>formula</b>: balance = balance + deltaSum </p>
	 * 
	 * @param accountId - account id
	 * @param deltaSum - sum to add/remove
	 * @throws UbsSecuityException 
	 */
	void updateBalance(Long accountId, double deltaSum) throws UbsSecuityException;
	
}
